<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            //创建一个具有iterator规范的函数
            function makeIterator(arr = []) {
                let currentIndex = 0;
                return {
                    next: function () {
                        return currentIndex < arr.length
                            ? {
                                  value: arr[currentIndex++],
                                  done: false,
                              }
                            : {
                                  value: arr[currentIndex++],
                                  done: true,
                              };
                    },
                };
            }
            let newArr = makeIterator([1, 2, 3, 4, 5]);
            console.log(newArr.next(), "aaa");
            console.log(newArr.next(), "nbbb");
            console.log(newArr.next(), "aaa");
            console.log(newArr.next(), "nbbb");
            console.log(newArr.next(), "m");
            console.log(newArr.next(), "nbbb"); //unfindermn
            console.log(newArr.next(), "m");
        </script>
    </body>
</html>
